
local mt = ac.skill['闪电链']
mt.art = [[ReplaceableTextures\CommandButtons\BTNGlacier.blp]]
mt.targettype = "物体"
mt.range = 800
mt.cool = 6
mt.damage = 100         --造成伤害
mt.damage_area = 600    --伤害范围
mt.damage_count = 6
mt.damage_type = '魔法' --伤害类型
mt.lightning1 = '闪电链主'
mt.lightning2 = '闪电链次'
--特效模型
mt.target_art = [[Abilities\Weapons\Bolt\BoltImpact.mdl]]

function mt:on_cast_shot()
    local target = self.target
    self:shot_lightning(target)
end


--发射主闪电
function mt:shot_lightning(target)
    local hero = self.owner
    ac.lightning({
        id = self.lightning1,
        from = hero,
        to = target,
        time = 0.5,
    })
    self.damage_count = self.damage_count - 1
    target:add_effect(self.target_art):remove()
    ac.wait(150,function()
        target:damage{
            damage_type = self.damage_type,
            source = hero,
            damage = self.damage,
            skill = self,
        }

        if self.damage_count>0 then
            self.selector = ac.selector('unit'):enemy(hero):is_not(target)
            local new = self.selector:range(target,self.damage_area):random()
            if new then
                self:shot_lightning2(target,new)
            end
        end
    end)
    
end


--发射子闪电
function mt:shot_lightning2(start,target,count)
    local hero = self.owner
    local selector = self.selector or ac.selector('unit'):enemy(hero)
    ac.lightning({
        id = self.lightning2 or self.lightning1,
        from = start,
        to = target,
        time = 0.5,
    })
    self.damage_count = self.damage_count - 1
    target:add_effect(self.target_art):remove()
    ac.wait(150,function()
        target:damage{
            damage_type = self.damage_type,
            source = hero,
            damage = self.damage,
            skill = self,
        }

        if self.damage_count>0 then
            selector = selector:is_not(target)
            local new = selector:range(target,self.damage_area):random()
            if new then
                self:shot_lightning2(target,new)
            end

        end
    end)
end